package sg.edu.nus.iss.vmcs.maintenance;

/*
 * Copyright 2011 ISS.
 * The contents contained in this document may not be reproduced in any
 * form or by any means, without the written permission of ISS, other
 * than for the purpose for which it has been supplied.
 *
 */


/**
 * This class represents controller for managing and controlling the
 * entry to the system by the maintainer. The instance of this class
 * manages and controls entry to maintenance panel. 
 *
 * @version 1.0  07/12/2011
 * @author Team 7S - SE19
 */

public class AccessManager {
	private MaintenanceController mctrl;
	private Password pswd;
	private boolean loginState = false;

/**	
 * This constructor will create a new instance of the Access Manager object and
 * one instance of the password object.
 * @param mc Maintenance Controller
 * @see MaintenanceController
 * @see Password
 */
	public AccessManager(MaintenanceController mc) {
		mctrl = mc;
		pswd = new Password();
	}

/**
 * This operation will close down the access manager functions
 */	
	public void closeDown() {
	}

/**
 * The operation send a received password string to the password object for
 * validation. Then instruct the password box to become deactivated
 * @param ps  Password String
 * @see MaintenanceController
 * @see Password
 */
	
	public void processPassword(String ps) {
		boolean psr;

		psr = pswd.validatePassword(ps);
		loginState = psr;
		mctrl.loginMaintainer(psr);
	}

/**
 * This operation retrieves the login state.
 * @return boolean the login state - login (TRUE) / logout (FALSE)
 */
	public boolean getLoginState() {
		return loginState;
	}

/**
 * This operation sets the state as logout
 */	
	public void logout() {
		loginState = false;
	}
}